<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>模板管理-计划管理信息列表</title>
    <script src="/scripts/boot.js"></script>
    <style>
        html,body{
            margin:0;padding: 0;border:0;width:100%;height:100%;overflow:hidden;
        }
        body{
        	background: #ffffff!important;
            padding:20px;
        }
    </style>
</head>
<body>
<div class="title-list mb-20"><span class="title-listbg"></span><span>模板信息列表</span></div>
<div id="qForm"  class="mini-toolbar1" style="border-bottom:0;padding:0px;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <div class="mb-20 position-rel">
                    <span class="search-title search-ml20">模板名称</span><input id = "name" name="name" class="mini-textbox search-200px"   value="">
                    <a class="add-botton search-ml60" onclick="list.search()">查询</a>
                    <a class="resetting-btn search-ml20" onclick="list.reset()">重置</a>
                </div>
            </td>
        </tr>
    </table>
</div>
<div class="container">
    <div class="mini-clearfix mb-10">
        <div class="mini-col-6 mini-col-sm-3">
            <a class="plan-btn mR-20"  onclick="list.addOrEdit('new')"><span class="add-bg"></span>新增</a>
        </div>
    </div>
</div>
<div class="mini-fit">
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" url="/planTemplete/listByPage" sizeList="[5,10,20,50]" pageSize="20"  idField="user_id" multiSelect="true" pagerButtons="buttons" showEmptyText="true" emptyText="暂无数据" alwaysShowEmptyText="true">
        <div property="columns">
            <div type="indexcolumn" headerAlign="center" align="center">编号</div>
            <div field="name" width="200" headerAlign="center" allowSort="false">模板名称</div>
            <div field="typeName" width="100" headerAlign="center" align="center" allowSort="false">模板类型</div>
            <div field="professionalType" width="100" headerAlign="center" align="center" allowSort="false">专项业务类型</div>
            <div field="createUserName" width="100" headerAlign="center" align="center" allowSort="false">创建人</div>
            <div field="createDate" width="100" headerAlign="center" align="center" allowSort="false" renderer="ondayRenderer">创建时间</div>
            <div field="state" width="100" headerAlign="center" align="center" allowSort="false" renderer="rendererState">审批状态</div>
            <div name="action" width="100" headerAlign="center" align="center">操作</div>
        </div>
    </div>
</div>
<script type="text/javascript">
	var grid,post_flag=false;
    var list = {
    //页面初始化
        init: function() {
            mini.parse();
            grid = mini.get("datagrid1");
            grid.load();
            grid.on("drawcell",function (e) {
                var column = e.column;
                var record = e.record;
               	if (column.name == "action") {
                    e.cellHtml = '<a class="check-botton" href="javascript:list.view()">查看</a>' +
                    ((record.state ==0 )?'<a class="check-botton btn-bd" href="javascript:list.audit()">发送审批</a>':"")+
                    ((record.state ==0 || record.state ==3)?'<a class="check-botton btn-bd" href="javascript:list.remove()">删除</a>':"");
               	}
            });
        },
        //审核
        audit:function () {
           if(post_flag){
        	   mini.alert("已经发送审批");
        	   return;
           };
    	   var row = grid.getSelected(); 
   		   post_flag=true;
           $.ajax({
				type : "post",
				url : "/loggerService/startPost",
				data : {"id":row.id,"formSign":"CDJHGLJHBZMB_01","workFlowId":"CDJHGLJHBZMBSP","jumpUrl":"/templet/planTemplet/workflow.html?id="+row.id,"url":"/act/taskApi/start","exampleEntity":"planTemplete"},
				success : function(msg) {
					if(msg.message==="ok"){
						list.updateAuditState(row.id);
					}
					post_flag=false;
				}
			}); 
        }, //改变数据状态
        updateAuditState: function(pid){
        	 $.ajax({
	        	  url:"/planTemplete/audit",
	        	  data:{"templeteId":pid},
	        	  success:function(data){
	                  grid.reload();
	        		  if(data.state){
	        			  CloseWindow('close')
	        		  }
	        	  }
        	 });
		},
      //新增或编辑
        addOrEdit: function (opt) {
            mini.open({
                url: "/templet/planTemplet/new.html",
                title: (opt=="edit"?"编辑":"新增")+"计划模板", width: 1100, height: 600,
                onload: function () {
                	if(opt=="edit"){
                		var row = grid.getSelected();
               		    var data = {"id": row.id,"state":opt};
                	}else{
                		 var data = {"state":opt};
                	}
                	var iframe = this.getIFrameEl();
                    iframe.contentWindow.view.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        },
    //    查看
        view: function(){
            var row = grid.getSelected();
            if (row) {
                mini.open({
                    url: "/templet/planTemplet/view.html",
                    title: "模板数据", width: $(window.parent.document).width()-280, height: 700,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = {"id": row.id,"templeteName":row.name};
                        iframe.contentWindow.view.SetData(data);
                    },
                    ondestroy: function (action) {
                        grid.reload();
                    }
                });

            } else {
                alert("请选中一条记录");
            }
        },
    //    查询
        search: function () {
            var data = {
                "name": mini.get("name").getValue()
            };
            grid.load(data);
        },
    //重置
        reset:function(){
            var form = new mini.Form("qForm");
            form.reset();
            grid.load()
        },
    //    删除
        remove: function () {
            var row = grid.getSelected();
            if (row) {
                if (confirm("确定删除选中记录？")) {
                    $.ajax({
                        url: "/planTemplete/del?id=" + row.id,
                        type : "post",
                        success: function (text) {
                            if (text.state) {
                                grid.reload();
                            } else {
                                mini.showMessageBox({
                                    showModal: false,
                                    width: 250,
                                    title: "提示",
                                    iconCls: "mini-messagebox-warning",
                                    message: text.message,
                                });

                            }
                        }
                    });

                }
            } else {
                alert("请选中一条记录");
            }
        }
    }
    list.init();
    
    function rendererState(e){
    	if(e.value == 0){
    		return "未提交";
    	}else if (e.value == 1){
    		return "审批中"
    	}else if (e.value == 2){
    		return "通过"
    	}else if (e.value == 3){
    		return "未通过"
    	}
    }
</script>
</body>
</html>